
/**
 * 防抖
 * @param {*} fun 方法
 * @param {*} delay 延迟时间
 * @returns 
 */
const debounce = function () {
    let time = null;
    function _(fun, delay = 200) {
        if (!fun || typeof fun !== 'function') { return }
        clearTimeout(time);
        time = setTimeout(() => {
            fun()
        }, delay);
    }
    return {
        run: _
    }
}
/**
 * 节流
 *  @param 执行方法
 *  @param 延迟
 */
let t = true;
const throttle = function (fun, delay = 200) {
    if (!fun || typeof fun !== 'function') { return }
    if (t) {
        fun();
        t = false;
        setTimeout(() => {
            t = true
        }, delay)
    }
}
export {
    debounce,
    throttle
}